'''
=========================
!/usr/bin/env python
_*_ coding:utf-8 _*_

@Time : 2020/7/22 15:05
@Coder: xh
@IDE  : PyCharm
=========================
'''
import time
import re
from wxpy import *
from selenium import webdriver
from PIL import  Image, ImageDraw, ImageFont

options = webdriver.ChromeOptions()
# options.add_argument('--headless')
url = 'https://www.pmtown.com/archives/category/%e6%97%a9%e6%8a%a5'
driver = webdriver.Chrome(options=options)
driver.get(url)
driver.maximize_window()

link = driver.find_element_by_xpath(
    '/html/body/main/div/div[2]/div[1]/div[2]/div[1]/div[1]/a').get_attribute('href')

driver.close()

driver2 = webdriver.Chrome(options=options)
driver2.get(link)
driver2.maximize_window()
time.sleep(2)

headline = driver2.find_element_by_xpath('/html/body/main/div/div[2]/div[1]/div[1]/div/div[2]/h1').text
print(headline)
texts = driver2.find_element_by_xpath('/html/body/main/div/div[2]/div[1]/div[1]/div/div[2]/p[1]').text
driver2.close()
pattern = re.compile( r'】(.*)【',re.M)
texts = pattern.findall(texts)
print(texts)

# text_list = texts.split('\n')[2:12:2]

# header = '早报'
# title = '由Python自动生成'
#
# img = './true.jpg'
# new_img = './daily1.jpg'
# compress_img = 'daily.jpg'  # 压缩后的图片
#
# # 设置字体样式
# font_type = 'C:/Windows/Fonts/simkai.ttf'
# font_medium_type = 'C:/Windows/Fonts/simkai.ttf'
# header_font = ImageFont.truetype(font_medium_type, 50)
# title_font = ImageFont.truetype(font_medium_type,20)
# font = ImageFont.truetype(font_type, 16)
# color = "#726053"
# color1 = "#294E76"
#
# # 打开图片
# image = Image.open(img)
# draw = ImageDraw.Draw(image)
# width, height = image.size
# print(width, height)
#
# # header头
# header_x = 105
# header_y = 20
# draw.text((header_x, header_y), u'%s' % header, color, header_font)
#
# # 标题
# title_x = header_x - 40
# title_y = header_y + 50
# draw.text((title_x, title_y), u'%s' % title, color1, title_font)
#
# # 当前时间
# cur_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
# cur_time_x = 75
# cur_time_y = title_y+30
# cur_time_font = ImageFont.truetype(font_type, 20)
# draw.text((cur_time_x, cur_time_y), u'%s' %
#           cur_time, color, cur_time_font)
#
# # 绘制列表
#
#
# def draw_info(x, y, the_list, linehigh, title_text):
#     draw.text((x, y), u'%s' % (title_text), color, font)
#     for num, info in enumerate(the_list):
#         height = num * linehigh
#         draw.text((x, y + height + 30), u'%s' % (info), color, font)
#
#
# linewith = 20
# linehigh = 20
# p_fenge = 20
#
# # 绘制科技
# keji_x = 25
# keji_y = title_y + 30
# title_text = ''
# keji_newlist = text_list
# draw_info(keji_x, keji_y, keji_newlist, linehigh, title_text)
#
# image.save(new_img, 'jpeg')
#
# bot = Bot()
#
# myfriends = bot.friends().search(u'风吹沙')[0]
# myfriends.send('python自动早报到了')
# myfriends.send_image('daily1.jpg')
